package com.kenliang.netty.rpc.spring;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * @author KenLiang
 * @description:
 * @date Created in 3:38 PM 2019/3/21.
 */
public class NettyRpcReferenceParser implements BeanDefinitionParser {
    @Override
    public BeanDefinition parse(Element element, ParserContext parserContext) {
        String id  = element.getAttribute("id");
        String interfaceName = element.getAttribute("interfaceName");
        String ipAddr = element.getAttribute("ipAddr");

        RootBeanDefinition beanDefinition = new RootBeanDefinition();
        beanDefinition.setLazyInit(false);
        beanDefinition.setBeanClass(NettyRpcReference.class);

        beanDefinition.getPropertyValues().addPropertyValue("interfaceName",interfaceName);
        beanDefinition.getPropertyValues().addPropertyValue("ipAddr",ipAddr);

        parserContext.getRegistry().registerBeanDefinition(id,beanDefinition);
        return beanDefinition;
    }
}
